package com.yang.action;

import com.yang.entity.Address;
import com.yang.service.AddressService;
import com.yang.util.RespEntity;
import com.yang.util.RespUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/AddressSava")
public class AddressSavaAction extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String userid = req.getParameter("userid");
        String def = req.getParameter("def");
        String contacts = req.getParameter("contacts");
        String tel = req.getParameter("tel");
        String address = req.getParameter("address");
        //创建对象
        Address ads=new Address();
        //封装数据
        ads.setUserid(Integer.parseInt(userid));
        ads.setDef(0);
        ads.setContacts(contacts);
        ads.setTel(tel);
        ads.setAddress(address);
        AddressService addressService=new AddressService();
        RespEntity respEntity = addressService.savaAddress(ads);
        RespUtil.sendJSON(resp,respEntity);
    }
}
